using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class PlayerPassHandler : MonoBehaviour
{
    [SerializeField]
    private GameObject _passInAnim;
    [SerializeField]
    private GameObject _passOutAnim;

    public void StartPass(PlatformPlayer player, Action onEnd)
    {
        StartCoroutine(PassCoroutine(player, onEnd));
    }

    private IEnumerator PassCoroutine(PlatformPlayer player, Action onEnd)
    {
        player.Hide = true;
        Vector3 oppositePosition = player.OppositePosition;
        GameObject passIn = Instantiate(_passInAnim);
        passIn.transform.position = player.transform.position;
        GameObject passOut = Instantiate(_passOutAnim);
        passOut.transform.position = oppositePosition;
        SwitchController.Instance.SwitchWorld();
        yield return new WaitForSeconds(0.5f);
        player.transform.position = oppositePosition;
        player.Hide = false;
        Destroy(passIn);
        Destroy(passOut);
        onEnd?.Invoke();
        Destroy(gameObject);
    }
}
